
export namespace userWeapp {

    export const login = async (): Promise<string> => {
		return new Promise((resolve,reject)=>{
			uni.login({
			  provider: 'weixin', //使用微信登录
			  success:  (loginRes)=> {
			    console.log('weapp login',loginRes);
				if (!loginRes.code) {
				    console.error('登录失败！' + loginRes.errMsg)
				    reject('登录失败,请重试!');
				}else{
					const token = loginRes.code ?? '';
					resolve(token)
				}
			  },
			  fail:(error)=>{
				  reject(error);
			  }
			});
		})
    }

    export const bindMobile = async (code: string): Promise<string> => {
        try {
            // const res = await webAPIs.v1.weixin.phoneNumber.call({ code: code });
			const res :any={};
            const mobile = res.rows.phoneNumber ?? "";
            if (mobile) {
                return Promise.resolve(mobile);
            } else {
                return Promise.reject(res.message || "未获取到手机号");
            }
        } catch (error) {
            return Promise.reject(error);
        }
    }

    // export const updateUser = async (updateUser: webAPIsV1models.AuthRegisterInput) => {
    //     try {
    //         const res = await webAPIs.v1.weixin.updateUser.call(updateUser);
    //         userStore.setUserInfo(res.data);
    //         return Promise.resolve(res);
    //     } catch (error) {
    //         return Promise.reject(error);
    //     }
    // }
}
